From: Ian Campbell Date: Thu, 5 Nov 2015 14:46:12 +0000 (+0000) Subject: tools: pygrub: if partition table is empty, try treating as a whole disk X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~2270 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=fb31b1475f1bf179f033b8de3f0e173006fd77e9;p=xen.git tools: pygrub: if partition table is empty, try treating as a whole disk pygrub (in identify_disk_image()) detects a DOS style partition table via the presence of the 0xaa55 signature at the end of the first sector of the disk. However this signature is also present in whole-disk configurations when there is an MBR on the disk. Many filesystems (e.g. ext[234]) include leading padding in their on disk format specifically to enable this. So if we think we have a DOS partition table but do not find any actual partition table entries we may as well try looking at it as a whole disk image. Worst case is we probe and find there isn't anything there. This was reported by Sjors Gielen in Debian bug #745419. The fix was inspired by a patch by Adi Kriegisch in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=745419#27 Tested by genext2fs'ing my /boot into a new raw image (works) and then: dd if=/usr/lib/grub/i386-pc/g2ldr.mbr of=img conv=notrunc bs=512 count=1 to add an MBR (with 0xaa55 signature) to it, which after this patch also works. Signed-off-by: Ian Campbell Acked-by: Wei Liu Acked-by: Ian Jackson Cc: 745419-forwarded@bugs.debian.org --- diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub index e4aedda5f3..40f95843be 100755 --- a/tools/pygrub/src/pygrub +++ b/tools/pygrub/src/pygrub @@ -156,6 +156,11 @@ def get_partition_offsets(file): else: part_offs.append(offset) + # We thought we had a DOS partition table, but didn't find any + # actual valid partition entries. This can happen because an MBR + # (e.g. grubs) may contain the same signature. + if not part_offs: part_offs = [0] + return part_offs class GrubLineEditor(curses.textpad.Textbox):